package com.smt.ejb3.tutoria.client;

import java.util.List;

import javax.naming.InitialContext;
import javax.naming.NamingException;

import com.smt.ejb3.tutoria.namedquery.Student1;
import com.smt.ejb3.tutoria.namedquery.StudentManager1;


public class Student1Client {
	public static void main(String[] args) {
		
		Student1 stu = new Student1();
		stu.setName("Old Sun");
		stu.setAge(22);
		stu.setAddress("Gungahlin");
		
		Student1 stu2 = new Student1();
		stu2.setName("Old Chang");
		stu2.setAge(21);
		stu2.setAddress("Ainslie");
		
		
		try {
			InitialContext ctx = new InitialContext();

			StudentManager1 manager = (StudentManager1) ctx
					.lookup("StudentManager1Bean/remote");
			
			/* Save Student */
//			manager.saveStudent(stu);
//			manager.saveStudent(stu2);
			
			/* Find Student */
			
//			Student1 s = manager.findStudent("Old Chang");
//			System.out.println(s);
//			try {
//				s = manager.findStudent("Old Chang2");
//			} catch (Exception e) {
//				System.out.println("Not Found");
//			}
			
			Student1 s = manager.findStudent2("Old Chang");
			System.out.println(s);
			try {
				s = manager.findStudent2("Old Chang2");
			} catch (Exception e) {
				System.out.println("Not Found");
			}
			
			
//			List<Student1> ss = manager.findAllStudents();
//			System.out.println(ss);
			
		} catch (NamingException ex) {
			ex.printStackTrace();
		}
	}
}
